package com.tanhua.common.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.common.mapper.LogMapper;
import com.tanhua.common.pojo.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogService {

    @Autowired
    private LogMapper logMapper;

    public IPage<Log> queryLogByList(QueryWrapper<Log> queryWrapper,  Page<Log> logPage) {
        return logMapper.selectPage(logPage, queryWrapper);
    }
    public void saveLog(Log log){
        logMapper.insert(log);
    }

    public Log queryLogByUserId(Long userId){
        QueryWrapper<Log> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",userId);
        queryWrapper.orderByDesc("log_time");
        List<Log> logs = logMapper.selectList(queryWrapper);
        if (logs.size() != 0){
            return logs.get(0);
        }
        return null;
    }
}
